﻿function summit_add_column() {
    $(".alert-success").remove(); $(".alert-danger").remove();
    $("#Name").val("");
    $("#form-field-select-1").val("0");
    $("#form-field-select-2").val("");
    $("#Remark").val("");
    var dialog = $("#dialog-message").removeClass('hide').dialog({
        modal: true,
        title: "<div class='widget-header widget-header-small'><h4 class='smaller'><i class='icon-ok'></i>添加导航栏新项</h4></div>",
        title_html: true,
        buttons: [
            {
                text: "添加",
                "class": "btn btn-primary btn-xs",
                click: function () {
                    var s = "";
                    s = $.ajax({
                        type: "POST",
                        url: "AjaxAction.ashx",
                        data: {
                            dowhat: "add_column",
                            Name: $("#Name").val(),
                            ParentID: $("#form-field-select-1").val(),
                            ModelID: $("#form-field-select-2").val(),
                            ColumnLogo: $("#ColumnLogo").val(),
                            Remark: $("#Remark").val(),

                        },
                        async: false
                    }).responseText;
                    if (s == "success") {
                        $(".alert-success").remove(); $(".alert-danger").remove(); $("#form_start").before("<div class='alert alert-block alert-success'><button type='button' class='close' data-dismiss='alert'><i class='icon-remove'></i></button><small><strong><i class='icon-ok'></i>&nbsp;&nbsp;&nbsp;&nbsp;添加成功</strong> </small></div>");
                        $("#Name").val("");
                        $("#form-field-select-1").val("0");
                        $("#form-field-select-2").val("");
                        $("#Remark").val("");
                    }
                    else { $(".alert-success").remove(); $(".alert-danger").remove(); $("#form_start").before("<div class='alert alert-danger'><button type='button' class='close' data-dismiss='alert'><i class='icon-remove'></i></button><small><strong><i class='icon-remove'></i>&nbsp;&nbsp;&nbsp;&nbsp;错误!&nbsp;&nbsp;&nbsp;&nbsp;</strong>" + s + "</small></div>"); }
                }
            },
            {
                text: "取消",
                "class": "btn btn-xs",
                click: function () {
                    $(this).dialog("close");
                }
            }
        ]
    });

    /**
    dialog.data( "uiDialog" )._title = function(title) {
        title.html( this.options.title );
    };
    **/
}
function summit_update_column(ID, Name, ParentID, ModelID, ColumnLogo, Remark) {
    $(".alert-success").remove(); $(".alert-danger").remove();
    $("#Name").val(Name);
    $("#form-field-select-1").val(ParentID);
    $("#form-field-select-2").val(ModelID);
    $("#Remark").val(Remark);
    $("#ColumnLogo").val(ColumnLogo);
    var dialog = $("#dialog-message").removeClass('hide').dialog({
        modal: true,
        title: "<div class='widget-header widget-header-small'><h4 class='smaller'><i class='icon-check green'></i>修改导航栏项</h4></div>",
        title_html: true,
        buttons: [
            {
                text: "修改",
                "class": "btn btn-success btn-xs",
                click: function () {
                    var s = "";
                    s = $.ajax({
                        type: "POST",
                        url: "AjaxAction.ashx",
                        data: {

                            dowhat: "update_column",
                            ID: ID,
                            Name: $("#Name").val(),
                            ParentID: $("#form-field-select-1").val(),
                            ModelID: $("#form-field-select-2").val(),
                            ColumnLogo: $("#ColumnLogo").val(),
                            Remark: $("#Remark").val(),

                        },
                        async: false
                    }).responseText;
                    if (s == "success") {
                        $(".alert-success").remove(); $(".alert-danger").remove(); $("#form_start").before("<div class='alert alert-block alert-success'><button type='button' class='close' data-dismiss='alert'><i class='icon-remove'></i></button><small><strong><i class='icon-ok'></i>&nbsp;&nbsp;&nbsp;&nbsp;修改成功</strong> </small></div>");
                    }
                    else { $(".alert-success").remove(); $(".alert-danger").remove(); $("#form_start").before("<div class='alert alert-danger'><button type='button' class='close' data-dismiss='alert'><i class='icon-remove'></i></button><small><strong><i class='icon-remove'></i>&nbsp;&nbsp;&nbsp;&nbsp;错误!</strong> " + s + "</small></div>"); }
                }
            },
            {
                text: "取消",
                "class": "btn btn-xs",
                click: function () {
                    $(this).dialog("close");
                }
            }
        ]
    });

    /**
    dialog.data( "uiDialog" )._title = function(title) {
        title.html( this.options.title );
    };
    **/
}

function summit_delete_column(ID) {
    var dialog = $("#dialog-confirm").removeClass('hide').dialog({
        resizable: false,
        modal: true,
        title: "<div class='widget-header'><h4 class='smaller'><i class='icon-warning-sign red'></i>删除导航栏项</h4></div>",
        title_html: true,
        buttons: [
            {
                html: "<i class='icon-trash'></i>&nbsp; 删除",
                "class": "btn btn-danger btn-xs",
                click: function () {
                    var s = "";
                    s = $.ajax({
                        type: "POST",
                        url: "AjaxAction.ashx",
                        data: {
                            dowhat: "delete_column",
                            ID: ID
                        },
                        async: false
                    }).responseText;
                    if (s == "success") {
                        window.location.href = "Default.aspx" + location.search;
                    }
                }
            }
            ,
            {
                html: "<i class='icon-remove'></i>&nbsp; 取消",
                "class": "btn btn-xs",
                click: function () {
                    $(this).dialog("close");
                }
            }
        ]
    });
};

function summit_clear() {
    window.location.href = "Default.aspx" + location.search;
}
function summit_sort_column() {
    var dialog = $("#dialog-success").removeClass('hide').dialog({
        resizable: false,
        modal: true,
        title: "<div class='widget-header'><h4 class='smaller'><i class='icon-ok'></i>操作提示</h4></div>",
        title_html: true,
        buttons: [
            {
                html: "<i class='icon-ok'></i>&nbsp; 确定",
                "class": "btn btn-primary btn-xs",
                click: function () {

                    var $FirstClass = $(".FistClass").children();
                    var F = "";
                    for (var i = 0; i < $FirstClass.length; i++) {

                        F = $.ajax({
                            type: "POST",
                            url: "AjaxAction.ashx",
                            data: {
                                dowhat: "sort_column",
                                ID: $(".FistClass").children().eq(i).attr("data-id"),
                                OrderID: i,
                                ParentID: "0",
                            },
                            async: false
                        }).responseText;
                        if (F == "faild") {
                            return;
                        }
                    }
                    var $SecondClassSum = $(".FistClass li ol");
                    var S = "";
                    for (var j = 0; j < $SecondClassSum.length; j++) {
                        var ParentID = $(".FistClass li ol").eq(j).parent().attr("data-id");
                        var $SecondChildren = $(".FistClass li ol").eq(j).children();
                        for (var k = 0; k < $SecondChildren.length; k++) {
                            S = $.ajax({
                                type: "POST",
                                url: "AjaxAction.ashx",
                                data: {
                                    dowhat: "sort_column",
                                    ID: $(".FistClass li ol").eq(j).children().eq(k).attr("data-id"),
                                    OrderID: k,
                                    ParentID: ParentID,
                                },
                                async: false
                            }).responseText;
                            if (S == "faild") { return; }
                        }
                    }
                    var $ThirdClassSum = $(".FistClass li ol li ol");
                    var T = "";
                    for (var j = 0; j < $SecondClassSum.length; j++) {
                        var ParentID = $(".FistClass li ol li ol").eq(j).parent().attr("data-id");
                        var $SecondChildren = $(".FistClass li ol li ol").eq(j).children();
                        for (var k = 0; k < $SecondChildren.length; k++) {
                            T = $.ajax({
                                type: "POST",
                                url: "AjaxAction.ashx",
                                data: {
                                    dowhat: "sort_column",
                                    ID: $(".FistClass li ol li ol").eq(j).children().eq(k).attr("data-id"),
                                    OrderID: k,
                                    ParentID: ParentID,
                                },
                                async: false
                            }).responseText;
                            if (T == "faild") { return; }
                        }
                    }
                    if (S != "faild" || T != "faild" || F != "faild") {
                        window.location.href = "Default.aspx" + location.search;
                    }
                }
            },

        ]
    });
}